package com.king.controller;


import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.king.common.lang.Result;
import com.king.entity.MUserMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.king.controller.BaseController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author KING
 * @since 2020-09-01
 */
@RequestMapping("/message")
@Controller
public class MUserMessageController extends BaseController {
    @ResponseBody
    @PostMapping("/remove")
    public Result delUserMessage(Long id,boolean all) {
        boolean remove = this.mUserMessageService.remove(new QueryWrapper<MUserMessage>()
                .eq("to_user_id", getProfileId())
                .eq(!all, "id", id)
        );
        return remove ? Result.success().action("/user/message"): Result.fail("删除失败！");
    }

    @ResponseBody
    @PostMapping("/nums")
    public Map getNotReadMsgCount(){
        int count = this.mUserMessageService.count(new QueryWrapper<MUserMessage>()
                .eq("to_user_id", getProfileId())
                .eq("status", "0")
        );

        return MapUtil.builder("status",0).put("count",count).build();
    }
}
